package com.edu.producerAndConsumer;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class Producer implements Runnable {
    private final Clerk clerk;

    @Override
    public void run() {
        while (true) {
            synchronized (clerk) {
                try {
                    Thread.sleep(100);
                    if (clerk.getProduction() < Clerk.MAX_PRODUCTION) {
                        clerk.setProduction(clerk.getProduction() + 1);
                        System.out.println(Thread.currentThread().getName() + " -- 生产ing... 产品余量为" + clerk.getProduction());
                    } else
                        clerk.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}

